﻿using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;


public class IntoRiver : MonoBehaviour
{
    public GameObject splash;


    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Player")
        {
            GameObject.Find("Main Camera").GetComponent<CameraFollow>().enabled = false;
            Instantiate(splash, col.transform.position, transform.rotation);
            Destroy(GameObject.Find("HealthBar"));
            Destroy(col.gameObject);

            //StartCoroutine("ReloadGame");
            StartCoroutine(EndGame());
        }
        else if (col.tag == "Rival")
        {
            GameObject.Find("Main Camera").GetComponent<CameraFollow>().enabled = false;
            Instantiate(splash, col.transform.position, transform.rotation);
            Destroy(GameObject.Find("CopyHealthBar"));
            Destroy(col.gameObject);
        }
        else 
        {
            //Debug.Log(col.transform.position);
            //Debug.Log();
            Instantiate(splash, col.transform.position, transform.rotation);
            Destroy(col.gameObject);
        }
        
    }

    IEnumerator ReloadGame()
    {
        Debug.Log("re");
        yield return new WaitForSeconds(2);
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
    }

    IEnumerator EndGame()
    {
        Debug.Log("end");
        yield return new WaitForSeconds(2);
        BattleManager.SendWinner();
    }
}
